package com.sghd.charge.module.payment.wxpay;

import com.github.wxpay.sdk.WXPayConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import static com.sghd.charge.module.model.ChargeConstant.*;

/**
 * @author frank
 */
@Service
public class WxConfig implements WXPayConfig {
    public static final String TRADE_TYPE = "APP";
    /** 证书*/
    private byte[] certData;

    @Value(WXPAY_APPID)
    private String appId;

    @Value(WXPAY_KEY)
    private String key;

    @Value(WXPAY_MCHID)
    private String mchId;

    @Value(WXPAY_NOTIFY_URL)
    private String notifyUrl;

    @Value(WXPAY_ORDER_TIMEOUT)
    private int timeout;

    @Value(WXPAY_CERT_PATH)
    private String certPath;

    public WxConfig() throws Exception {
//        String certPath = "/data/config/chidori/apiclient_cert.p12";
//        File file = new File(certPath);
//        InputStream certStream = new FileInputStream(file);
//        this.certData = new byte[(int) file.length()];
//        certStream.read(this.certData);
//        certStream.close();
    }

    @Override
    public String getAppID() {
        return appId;
    }

    @Override
    public String getMchID() {
        return mchId;
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public InputStream getCertStream() {
        return new ByteArrayInputStream(this.certData);
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 0;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 0;
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public int getTimeout() {
        return timeout;
    }
}
